home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / textfile / mac_faqs / puzz_faq / part02 < prev    next >
Encoding:
Internet Message Format  |  1995-01-01  |  59.2 KB

  1. Xref: bloom-picayune.mit.edu rec.puzzles:18137 news.answers:3069
  2. Newsgroups: rec.puzzles,news.answers
  3. Path: bloom-picayune.mit.edu!enterpoop.mit.edu!snorkelwacker.mit.edu!usc!wupost!uunet!questrel!chris
  4. From: uunet!questrel!chris (Chris Cole)
  5. Subject: rec.puzzles FAQ, part 2 of 15
  6. Message-ID: <puzzles-faq-2_717034101@questrel.com>
  7. Followup-To: rec.puzzles
  8. Summary: This posting contains a list of
  9.      Frequently Asked Questions (and their answers).
  10.      It should be read by anyone who wishes to
  11.      post to the rec.puzzles newsgroup.
  12. Sender: chris@questrel.com (Chris Cole)
  13. Reply-To: uunet!questrel!faql-comment
  14. Organization: Questrel, Inc.
  15. References: <puzzles-faq-1_717034101@questrel.com>
  16. Date: Mon, 21 Sep 1992 00:08:31 GMT
  17. Approved: news-answers-request@MIT.Edu
  18. Expires: Sat, 3 Apr 1993 00:08:21 GMT
  19. Lines: 1579
  20.  
  21. Archive-name: puzzles-faq/part02
  22. Last-modified: 1992/09/20
  23. Version: 3
  24.  
  25. ==> analysis/bugs.p <==
  26. Four bugs are placed at the corners of a square. Each bug walks directly
  27. toward the next bug in the clockwise direction. The bugs walk with
  28. constant speed always directly toward their clockwise neighbor. Assuming
  29. the bugs make at least one full circuit around the center of the square
  30. before meeting, how much closer to the center will a bug be at the end
  31. of its first full circuit?
  32.  
  33. ==> analysis/bugs.s <==
  34. Amorous Bugs
  35.  
  36. ANSWER: 1 - e^(-2*pi)
  37.  
  38.     Let O(t) be the angle at time t of bug 1 relative to its starting
  39.     point and r(O(t)) be its distance from the center of the square.
  40.     Bug 1's vector trajectory is (using a Cartesian coordinate system with
  41.     the origin at the center of the square):
  42.         (1) X1 = [r(O) * cos(O), r(O) * sin(O)]
  43.     By symmetry, bug 2's trajectory is the same only rotated by pi/2, viz.:
  44.         (2) X2 = [-r(O) * sin(O), r(O) * cos(O)]
  45.     Since bug 1 walks directly toward bug 2, the velocity of bug 1 must be
  46.     proportional to the vector from bug 1 to bug 2:
  47.         (3) d(X1)/d(t) = k * (X2 - X1)
  48.     Equating each component of the vector equation (3) yields:
  49.         (4) (d(r)/d(O) * cos(O) - r * sin(O)) * d(O)/d(t) = 
  50.             k * (-r * cos(O) - r * sin(O))
  51.         (5) (d(r)/d(O) * sin(O) + r * cos(O)) * d(O)/d(t) =
  52.             k * (-r * sin(O) + r * cos(O))
  53.     These equations are solved by:
  54.         (6) k = d(O)/d(t)
  55.     and:
  56.         (7) d(r)/d(O) = -r(O)
  57.     (7) is solved by:
  58.         (8) r(O) = e^-O
  59.     Constant speed gives:
  60.         (9) v^2 = constant = ((d(r)/d(O))^2+r^2)*(d(O)/d(t))^2
  61.     Substituting (8) into (9) yields (let V = v/sqrt(2)):
  62.         (10) d(O)/d(t) = V * e^O
  63.     Which is solved (using the boundary condition O(0) = 0) by:
  64.         (11) O(t) = -ln(1 - V * t)
  65.     Substituting (11) into (8) yields:
  66.         (12) r(t) = r(0) - V * t
  67.     The bug has made a full circle when O(T) = 2*pi; using (11):
  68.         (13) T = 1/V * (1 - e^(-2*pi))
  69.     Substituting T into (12) yields the answer:
  70.         (14) r(T) - r(0) = 1 - e^(-2*pi) 
  71.  
  72. ==> analysis/c.infinity.p <==
  73. What function is zero at zero, strictly positive elsewhere, infinitely
  74. differentiable at zero and has all zero derivitives at zero?
  75.  
  76. ==> analysis/c.infinity.s <==
  77. exp(-1/x^2)
  78.  
  79. This tells us why Taylor Series are a more limited device than they might be.
  80. We form a Taylor series by looking at the derivatives of a function at a given
  81. point; but this example shows us that the derivatives at a point may tell us
  82. almost nothing about its behavior away from that point.
  83.  
  84. ==> analysis/cache.p <==
  85. Cache and Ferry (How far can a truck go in a desert?)
  86. A pick-up truck is in the desert beside N 50-gallon gas drums, all full.
  87. The truck's gas tank holds 10 gallons and is empty.  The truck can carry
  88. one drum, whether full or empty, in its bed.  It gets 10 miles to the gallon.
  89. How far away from the starting point can you drive the truck?
  90.  
  91. ==> analysis/cache.s <==
  92. If the truck can siphon gas out of its tank and leave it in the cache,
  93. the answer is:
  94.         { 1/1 + 1/3 + ... + 1/(2 * N - 1) } x 500 miles.
  95.  
  96. Otherwise, the "Cache and Ferry" problem is the same as the "Desert Fox"
  97. problem described, but not solved, by Dewdney, July '87 "Scientific American".
  98.  
  99. Dewdney's Oct. '87 Sci. Am. article gives for N=2, the optimal distance
  100. of 733.33 miles.
  101.  
  102. In the Nov. issue, Dewdney lists the optimal distance of 860 miles for
  103. N=3, and gives a better, but not optimal, general distance formula.
  104.  
  105. Westbrook, in Vol 74, #467, pp 49-50, March '90 "Mathematical Gazette",
  106. gives an even better formula, for which he incorrectly claims optimality:
  107.  
  108.   For N = 2,3,4,5,6:
  109.      Dist = (600/1 + 600/3 + ... + 600/(2N-3))  +  (600-100N)/(2N-1)
  110.   For N > 6:
  111.      Dist = (600/1 + 600/3 + ... + 600/9)  +  (500/11 + ... + 500/(2N-3))
  112.  
  113. The following shows that Westbrook's formula is not optimal for N=8:
  114.  
  115.    Ferry  7 drums forward   33.3333 miles   (356.6667 gallons remain)
  116.    Ferry  6 drums forward   51.5151 miles   (300.0000 gallons remain)
  117.    Ferry  5 drums forward   66.6667 miles   (240.0000 gallons remain)
  118.    Ferry  4 drums forward   85.7143 miles   (180.0000 gallons remain)
  119.    Ferry  3 drums forward  120.0000 miles   (120.0000 gallons remain)
  120.    Ferry  2 drums forward  200.0000 miles   ( 60.0000 gallons remain)
  121.    Ferry  1 drums forward  600.0000 miles
  122.                           ---------------
  123.          Total distance = 1157.2294 miles
  124.    (Westbrook's formula = 1156.2970 miles)
  125.  
  126.        ["Ferrying n drums forward x miles" involves (2*n-1) trips,
  127.          each of distance x.]
  128.  
  129. Other attainable values I've found:
  130.    N      Distance
  131.   ---    ---------  (Ferry distances for each N are omitted for brevity.)
  132.     5    1016.8254
  133.     7    1117.8355
  134.    11    1249.2749
  135.    13    1296.8939
  136.    17    1372.8577
  137.    19    1404.1136  (The N <= 19 distances could be optimal.)
  138.    31    1541.1550  (I doubt that this N = 31 distance is optimal.)
  139.   139    1955.5509  (I'm sure that this N = 139 distance is not optimal.)
  140.  
  141. So...where's MY formula?
  142. I haven't found one, and believe me, I've looked.
  143.  
  144. I would be most grateful if someone would end my misery by mailing me
  145. a formula, a literature reference, or even an efficient algorithm that
  146. computes the optimal distance.
  147.  
  148. If you do come up with the solution, you might want to first check it
  149. against the attainable distances listed above, before sending it out.
  150. (Not because you might be wrong, but just as a mere formality to check
  151.  your work.)
  152.  
  153. [Warning:  the Mathematician General has determined that
  154.            this problem is as addicting as Twinkies.]
  155.  
  156. Myron P. Souris      | "If you have anything to tell me of importance,
  157. McDonnell Douglas    |  for God's sake begin at the end."
  158. souris@mdcbbs.com    |                            Sara Jeanette Duncan
  159.  
  160.  
  161. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  162.  
  163. The following output comes from some hack programs that I've used to
  164. empirically verify some proofs I've been working on.
  165.  
  166. Initial barrels:   12 (600 gallons)
  167. Attainable distance= 1274.175211
  168.                   Barrels  Distance      Gas
  169.                    Moved    covered     left
  170. >From depot   1:      10     63.1579   480.0000
  171. >From depot   2:       8     50.0000   405.0000
  172. >From depot   3:       7     37.5000   356.2500
  173. >From depot   4:       6     51.1364   300.0000
  174. >From depot   5:       5     66.6667   240.0000
  175. >From depot   6:       4     85.7143   180.0000
  176. >From depot   7:       3    120.0000   120.0000
  177. >From depot   8:       2    200.0000    60.0000
  178. >From depot   9:       1    600.0000     0.0000
  179.  
  180.  
  181. Initial barrels:   40 (2000 gallons)
  182. Attainable distance= 1611.591484
  183.                   Barrels  Distance      Gas
  184.                    Moved    covered     left
  185. >From depot   1:      40      2.5316  1980.0000
  186. >From depot   2:      33     50.0000  1655.0000
  187. >From depot   3:      28     50.0000  1380.0000
  188. >From depot   4:      23     53.3333  1140.0000
  189. >From depot   5:      19     50.0000   955.0000
  190. >From depot   6:      16     56.4516   780.0000
  191. >From depot   7:      13     50.0000   655.0000
  192. >From depot   8:      11     54.7619   540.0000
  193. >From depot   9:       9     50.0000   455.0000
  194. >From depot  10:       8     32.1429   406.7857
  195. >From depot  11:       7     38.9881   356.1012
  196. >From depot  12:       6     51.0011   300.0000
  197. >From depot  13:       5     66.6667   240.0000
  198. >From depot  14:       4     85.7143   180.0000
  199. >From depot  15:       3    120.0000   120.0000
  200. >From depot  16:       2    200.0000    60.0000
  201. >From depot  17:       1    600.0000     0.0000
  202.  
  203. ==> analysis/cats.and.rats.p <==
  204. If 6 cats can kill 6 rats in 6 minutes, how many cats does it take to
  205. kill one rat in one minute?
  206.  
  207. ==> analysis/cats.and.rats.s <==
  208. The following piece by Lewis Carroll first appeared in ``The Monthly
  209. Packet'' of February 1880 and is reprinted in _The_Magic_of_Lewis_Carroll_,
  210. edited by John Fisher, Bramhall House, 1973.
  211.  
  212. /Larry Denenberg
  213. larry@bbn.com
  214. larry@harvard.edu
  215.  
  216.  
  217.  
  218.  
  219.  
  220.                                  Cats and Rats
  221.  
  222.    If 6 cats kill 6 rats in 6 minutes, how many will be needed to kill 100
  223.    rats in 50 minutes?
  224.  
  225.    This is a good example of a phenomenon that often occurs in working
  226.    problems in double proportion; the answer looks all right at first, but,
  227.    when we come to test it, we find that, owing to peculiar circumstances in
  228.    the case, the solution is either impossible or else indefinite, and needing
  229.    further data.  The 'peculiar circumstance' here is that fractional cats or
  230.    rats are excluded from consideration, and in consequence of this the
  231.    solution is, as we shall see, indefinite.
  232.  
  233.    The solution, by the ordinary rules of Double Proportion, is as follows:
  234.        6 rats   :  100 rats  \
  235.                   >   :: 6 cats : ans.
  236.       50 min.   :    6 min.  /
  237.          .
  238.     . .  ans. = (100)(6)(6)/(50)(6) = 12
  239.  
  240.    But when we come to trace the history of this sanguinary scene through all
  241.    its horrid details, we find that at the end of 48 minutes 96 rats are dead,
  242.    and that there remain 4 live rats and 2 minutes to kill them in: the
  243.    question is, can this be done?
  244.  
  245.    Now there are at least *four* different ways in which the original feat,
  246.    of 6 cats killing 6 rats in 6 minutes, may be achieved.  For the sake of
  247.    clearness let us tabulate them:
  248.       A.  All 6 cats are needed to kill a rat; and this they do in one minute,
  249.           the other rats standing meekly by, waiting for their turn.
  250.       B.  3 cats are needed to kill a rat, and they do it in 2 minutes.
  251.       C.  2 cats are needed, and do it in 3 minutes.
  252.       D.  Each cat kills a rat all by itself, and take 6 minutes to do it.
  253.  
  254.    In cases A and B it is clear that the 12 cats (who are assumed to come
  255.    quite fresh from their 48 minutes of slaughter) can finish the affair in
  256.    the required time; but, in case C, it can only be done by supposing that 2
  257.    cats could kill two-thirds of a rat in 2 minutes; and in case D, by
  258.    supposing that a cat could kill one-third of a rat in two minutes.  Neither
  259.    supposition is warranted by the data; nor could the fractional rats (even
  260.    if endowed with equal vitality) be fairly assigned to the different cats.
  261.    For my part, if I were a cat in case D, and did not find my claws in good
  262.    working order, I should certainly prefer to have my one-third-rat cut off
  263.    from the tail end.
  264.  
  265.    In cases C and D, then, it is clear that we must provide extra cat-power.
  266.    In case C *less* than 2 extra cats would be of no use.  If 2 were supplied,
  267.    and if they began killing their 4 rats at the beginning of the time, they
  268.    would finish them in 12 minutes, and have 36 minutes to spare, during which
  269.    they might weep, like Alexander, because there were not 12 more rats to
  270.    kill.  In case D, one extra cat would suffice; it would kill its 4 rats in
  271.    24 minutes, and have 24 minutes to spare, during which it could have killed
  272.    another 4.  But in neither case could any use be made of the last 2
  273.    minutes, except to half-kill rats---a barbarity we need not take into
  274.    consideration.
  275.  
  276.    To sum up our results.  If the 6 cats kill the 6 rats by method A or B,
  277.    the answer is 12; if by method C, 14; if by method D, 13.
  278.  
  279.    This, then, is an instance of a solution made `indefinite' by the
  280.    circumstances of the case.  If an instance of the `impossible' be desired,
  281.    take the following: `If a cat can kill a rat in a minute, how many would be
  282.    needed to kill it in the thousandth part of a second?'  The *mathematical*
  283.    answer, of course, is `60,000,' and no doubt less than this would *not*
  284.    suffice; but would 60,000 suffice?  I doubt it very much.  I fancy that at
  285.    least 50,000 of the cats would never even see the rat, or have any idea of
  286.    what was going on.
  287.  
  288.    Or take this: `If a cat can kill a rat in a minute, how long would it be
  289.    killing 60,000 rats?'  Ah, how long, indeed!  My private opinion is that
  290.    the rats would kill the cat.
  291.  
  292.  
  293.  
  294. ==> analysis/e.and.pi.p <==
  295. Which is greater, e^(pi) or (pi)^e ?
  296.  
  297. ==> analysis/e.and.pi.s <==
  298. Put x = pi/e - 1 in the inequality e^x > 1+x  (x>0).
  299.  
  300. ==> analysis/functional/distributed.p <==
  301.      Find all f: R -> R, f not identically zero, such that
  302. (*)     f( (x+y)/(x-y) ) = ( f(x)+f(y) )/( f(x)-f(y) ).
  303.  
  304. ==> analysis/functional/distributed.s <==
  305. 1)  Assuming f finite everywhere, (*) ==> x<>y ==> f(x)<>f(y)
  306.  
  307. 2)  Exchanging x and y in (*) we see that f(-x) = -f(x).
  308.  
  309. 3)  a <> 0 ==> f((a-a)/(a+a)) = (f(a)-f(a))/(f(a)+f(a)) ==> f(0) = 0.
  310.  
  311. 4)  a <> 0 ==> f((a+0)/(a-0)) = f(a)/f(a) ==> f(1) = 1.
  312.  
  313. 5)  x<>y, y<>0 ==> f(x/y) =
  314. f( ((x+y)/(x-y) + (x-y)/(x-y)) / ((x+y)/(x-y) - (x-y)/(x-y)) = f(x)/f(y)
  315. ==> f(xy) = f(x)f(y) by replacing x with xy and by noting that
  316. f(x*1) = f(x)*1 and f(x*0) = f(x)*f(0).
  317.  
  318. 6)  f(x*x) = f(x)*f(x) ==> f(x) > 0 if x>0.
  319.  
  320. 7)  Let a=1+\/2, b=1-\/2; a,b satisfy (x+1)/(x-1) = x ==>
  321. f(x) = (f(x)+1)/(f(x)-1) ==> f(a)=a, f(b)=b.  f(1/\/2) = f((a+b)/(a-b))
  322. = (a+b)/(a-b) = 1/\/2 ==> f(2) = 2.
  323.  
  324. 8)  By induction and the relation f((n+1)/(n-1)) = (f(n)+1)/(f(n)-1)
  325. we get that f(n)=n for all integer n.  #5 now implies that f fixes
  326. the rationals.
  327.  
  328. 9)  If x>y>0 (*) ==> f(x) - f(y) = f(x+y)/f((x+y)/(x-y)) > 0 by #6.
  329. Thus f is order-preserving.
  330.  
  331. Since f fixes the rationals *and* f is order-preserving, f must be the
  332. identity function.
  333.  
  334. This was E2176 in _The American Mathematical Monthly_ (the proposer was
  335. R. S. Luthar).
  336.  
  337. ==> analysis/functional/linear.p <==
  338. Suppose f is non-decreasing with
  339.   f(x+y) = f(x) + f(y) + C   for all real x, y.
  340. Prove: there is a constant A such that f(x) = Ax - C  for all x.
  341. (Note: continuity of f is not assumed in advance.)
  342.  
  343. ==> analysis/functional/linear.s <==
  344. By induction f(mx) = m(f(x)+C)-C.  Let x=1/n, m=n and find that
  345. f(1/n) = (1/n)(f(1)+C)-C.  Now let x=1/n and find that f(m/n) =
  346. (m/n)(f(1)+C)-C.  f(-x+x) = f(-x) + f(x) + C ==> f(-x) = -2C - f(x)
  347. (since f(0) = -C) ==> f(-m/n) = -(m/n)(f(1)+C)-C.  Since f is
  348. monotonic ==> f(x) = x*(f(1)+C)-C for all real x (Squeeze Theorem).
  349.  
  350. ==> analysis/integral.p <==
  351. If f is integrable on (0,inf), and differentiable at 0, and a > 0, show:
  352.  
  353.  
  354.                   inf     ( f(x) - f(ax) )  
  355.                Int        ----------------  dx   = f(0) ln(a)
  356.                    0             x
  357.  
  358. ==> analysis/integral.s <==
  359. First, note that if f(0) is 0, then by substituting u=ax in
  360. the integral of f(x)/x, our integral is the difference of two
  361. equal integrals and so is 0 (the integrals are finite because f is
  362. 0 at 0 and differentiable there.  Note I make no requirement of
  363. continuity).
  364.  
  365. Second, note that if f is the characteristic function of the
  366. interval [0, 1]--- i.e.
  367.  
  368.         1, 0<=x<=1
  369.     f (x) =
  370.         0 otherwise
  371.  
  372. then a little arithmetic reduces our integral to that of
  373. 1/x from 1/a to 1 (assuming a>1; if a <= 1 the reasoning is similar),
  374. which is ln(a) = f(0)ln(a) as required.  Call this function g.
  375.  
  376. Finally, note that the operator which takes the function f to the
  377. value of our integral is linear, and that every function meeting the
  378. hypotheses (incidentally, I should have said `differentiable from the right',
  379. or else replaced the characteristic function of [0,1] above by that of
  380. (-infinity, 1]; but it really doesn't matter) is a linear combination of
  381. one which is 0 at 0 and g, to wit
  382.  
  383.     f(x) = f(0)g(x) + (f(x) - g(x)f(0)).
  384.  
  385. ==> analysis/period.p <==
  386. What is the least possible integral period of the sum of functions
  387. of periods 3 and 6?
  388.  
  389. ==> analysis/period.s <==
  390. Period 2.  Clearly, the sum of periodic functions of periods 2 and
  391. three is 6.  So take the function which is the sum of that function of
  392. period six and the negative of the function of period three and you
  393. have a function of period 2.
  394.  
  395. ==> analysis/rubberband.p <==
  396. A bug walks down a rubberband which is attached to a wall at one end and a car
  397. moving away from the wall at the other end. The car is moving at 1 m/sec while
  398. the bug is only moving at 1 cm/sec. Assuming the rubberband is uniformly and
  399. infinitely elastic, will the bug ever reach the car?
  400.  
  401. ==> analysis/rubberband.s <==
  402. Let w = speed of bug and N = ratio of car speed/bug speed = 100.  Paint N+1
  403. equally spaced stripes on the rubberband.  When the bug is standing on one
  404. stripe, the next stripe is moving away from him at a speed slightly < w
  405. (relative to him).  Since he is walking at w, clearly the bug can reach
  406. the next stripe.  But once he reaches that stripe, the next one is only
  407. receeding at < w.  So he walks on down to the car, one stripe at a time.
  408.  
  409. The bug starts gaining on the car when he is at the next to last stripe.
  410.  
  411. ==> analysis/series.p <==
  412. Show that in the series: x, 2x, 3x, .... (n-1)x (x can be any real number)
  413. there is at least one number which is within 1/n of an integer.
  414.  
  415. ==> analysis/series.s <==
  416. Throw 0 into the sequence; there are now n numbers, so some pair must
  417. have fractional parts within 1/n of each other; their difference is
  418. then within 1/n of an integer.
  419.  
  420. ==> analysis/snow.p <==
  421. Snow starts falling before noon on a cold December day.
  422. At noon a snowplow starts plowing a street.
  423. It travels 1 mile in the first hour, and 1/2 mile in the second hour.
  424. What time did the snow start falling??
  425.  
  426. You may assume that the plow's rate of travel is inversely proportioned
  427. to the height of the snow, and that the snow falls at a uniform rate.
  428.  
  429. ==> analysis/snow.s <==
  430. 11:22:55.077 am.
  431.  
  432. Method:
  433.  
  434. Let b = the depth of the snow at noon, a = the rate of increase in the
  435. depth.  Then the depth at time t (where noon is t=0) is at+b, the
  436. snowfall started at t_0=-b/a, and the snowplow's rate of progress is 
  437. ds/dt = k/(at+b).
  438.  
  439. If the snowplow starts at s=0 then s(t) = (k/a) log(1+at/b).  Note that
  440. s(2 hours) = 1.5 s(1 hour), or  log(1+2A/b) = 1.5 log(1+A/b), where
  441. A = (1 hour)*a.  Letting x = A/b we have (1+2x)^2 = (1+x)^3.  Solve for
  442. x and t_0 = -(1 hour)/x.
  443.  
  444. The exact answer is 11:(90-30 Sqrt[5]).
  445.  
  446. _American Mathematics Monthly_, April 1937, page 245
  447. E 275.  Proposed by J. A. Benner, Lafayette College, Easton. Pa.
  448.  
  449. The solution appears, appropriately, in the December 1937 issue,
  450. pp. 666-667.  Also solved by William Douglas, C. E. Springer,
  451. E. P. Starke, W. J.  Taylor, and the proposer.
  452.  
  453. See R.P. Agnew, "Differential Equations," 2nd edition, p. 39 ff.
  454.  
  455. ==> analysis/tower.p <==
  456. A number is raised to its own power. The same number is then raised to
  457. the power of this result. The same number is then raised to the power
  458. of this second result. This process is continued forever. What is the
  459. maximum number which will yield a finite result from this process?
  460.  
  461. ==> analysis/tower.s <==
  462. Tower of Exponentials
  463.  
  464. ANSWER: e^(1/e)
  465.  
  466.     Let N be the number in question and R the result of the process. Then
  467.     R can be defined recursively by the equation:
  468.         (1) R = N^R
  469.     Taking the logarithm of both sides of (1):
  470.         (2) ln(R) = R * ln(N)
  471.     Dividing (2) by R and rearranging:
  472.         (3) ln(N) = ln(R) / R
  473.     Exponentiating (3):
  474.         (4) N = R^(1/R)
  475.     We wish to find the maximum value of N with respect to R. Find the
  476.     derivative of N with respect to R and set it equal to zero:
  477.         (5) d(N)/d(R) = (1 - ln(R)) / R^2 = 0
  478.     For finite values of R, (5) is satisfied by R = e. This is a maximum of
  479.     N if the second derivative of N at R = e is less than zero.
  480.         (6) d2(N)/d2(R) | R=e = (2 * ln(R) - 3) / R^3 | R=e = -1 / e^3 < 0
  481.     The solution therefore is (4) at R = e:
  482.         (7) Nmax = e^(1/e)
  483.  
  484. ==> arithmetic/7-11.p <==
  485. A customer at a 7-11 store selected four items to buy, and was told
  486. that the cost was $7.11.  He was curious that the cost was the same
  487. as the store name, so he inquired as to how the figure was derived.
  488. The clerk said that he had simply multiplied the prices of the four
  489. individual  items.  The customer  protested  that  the four  prices     
  490. should have been ADDED,  not MULTIPLIED.  The  clerk said that that
  491. was OK with him, but, the result was still the same: exactly $7.11.
  492.  
  493. What were the prices of the four items?
  494.  
  495. ==> arithmetic/7-11.s <==
  496. The prices are: $1.20, $1.25, $1.50, and $3.16
  497.  
  498. $7.11 is not the only number which works.  Here are the first 160 such
  499. numbers, preceded by a count of distinct solutions for that price.
  500. Note that $7.11 has a single, unique solution.
  501.  
  502.        1 -  $6.44      1 -  $7.83      2 -  $9.20      3 - $10.89 
  503.        1 -  $6.51      1 -  $7.86      1 -  $9.23      1 - $10.95 
  504.        1 -  $6.60      3 -  $7.92      1 -  $9.24      2 - $11.00 
  505.        1 -  $6.63      1 -  $8.00      1 -  $9.27      1 - $11.07 
  506.        1 -  $6.65      1 -  $8.01      2 -  $9.35      1 - $11.13 
  507.        1 -  $6.72      1 -  $8.03      3 -  $9.36      1 - $11.16 
  508.        2 -  $6.75      5 -  $8.10      1 -  $9.38      1 - $11.22 
  509.        1 -  $6.78      1 -  $8.12      5 -  $9.45      2 - $11.25 
  510.        1 -  $6.80      1 -  $8.16      2 -  $9.48      2 - $11.27 
  511.        2 -  $6.84      2 -  $8.19      1 -  $9.54      1 - $11.30 
  512.        1 -  $6.86      1 -  $8.22      1 -  $9.57      1 - $11.36 
  513.        1 -  $6.89      1 -  $8.25      1 -  $9.59      1 - $11.40 
  514.        2 -  $6.93      3 -  $8.28      2 -  $9.60      2 - $11.43 
  515.        1 -  $7.02      3 -  $8.33      1 -  $9.62      2 - $11.52 
  516.        1 -  $7.05      1 -  $8.36      2 -  $9.63      2 - $11.55 
  517.        2 -  $7.07      1 -  $8.37      1 -  $9.66      2 - $11.61 
  518.        1 -  $7.08      2 -  $8.40      1 -  $9.68      1 - $11.69 
  519.        1 -  $7.11      1 -  $8.45      2 -  $9.69      1 - $11.70 
  520.        1 -  $7.13      2 -  $8.46      1 -  $9.78      1 - $11.88 
  521.        2 -  $7.14      1 -  $8.52      2 -  $9.80      1 - $11.90 
  522.        3 -  $7.20      5 -  $8.55      1 -  $9.81      1 - $11.99 
  523.        1 -  $7.25      1 -  $8.60      1 -  $9.87      1 - $12.06 
  524.        1 -  $7.26      4 -  $8.64      4 -  $9.90      1 - $12.15 
  525.        2 -  $7.28      1 -  $8.67      1 -  $9.92      1 - $12.18 
  526.        1 -  $7.29      1 -  $8.69      2 -  $9.99      1 - $12.24 
  527.        3 -  $7.35      1 -  $8.73      1 - $10.01      1 - $12.30 
  528.        1 -  $7.37      2 -  $8.75      1 - $10.05      1 - $12.32 
  529.        1 -  $7.47      1 -  $8.76      2 - $10.08      1 - $12.35 
  530.        1 -  $7.50      1 -  $8.78      1 - $10.17      2 - $12.42 
  531.        1 -  $7.52      5 -  $8.82      1 - $10.20      1 - $12.51 
  532.        4 -  $7.56      1 -  $8.85      2 - $10.26      1 - $12.65 
  533.        1 -  $7.62      1 -  $8.88      3 - $10.29      2 - $12.69 
  534.        4 -  $7.65      2 -  $8.91      3 - $10.35      1 - $12.75 
  535.        1 -  $7.67      1 -  $8.94      2 - $10.44      1 - $12.92 
  536.        2 -  $7.70      1 -  $8.96      1 - $10.53      1 - $12.96 
  537.        3 -  $7.74      3 -  $9.00      1 - $10.56      1 - $13.23 
  538.        1 -  $7.77      1 -  $9.02      1 - $10.64      1 - $13.41 
  539.        1 -  $7.79      2 -  $9.03      2 - $10.71      1 - $13.56 
  540.        2 -  $7.80      1 -  $9.12      3 - $10.80      1 - $14.49 
  541.        1 -  $7.82      2 -  $9.18      1 - $10.85      1 - $15.18 
  542.  
  543.  
  544. There are plenty of solutions for five summands.  Here are a few:
  545.  
  546.          $8.28  -- at least two solutions
  547.          $8.47  -- at least two solutions
  548.          $8.82  -- at least two solutions
  549. --
  550.      Mark Johnson       mark@microunity.com       (408) 734-8100
  551.  
  552. There may be many approximate solutions, for example: $1.01, $1.15, $2.41,
  553. and $2.54.  These sum to $7.11 but the product is 7.1100061.
  554.  
  555. ==> arithmetic/clock/day.of.week.p <==
  556. It's restful sitting in Tom's cosy den, talking quietly and sipping
  557. a glass of his Madeira.
  558.  
  559. I was there one Sunday and we had the usual business of his clock.
  560. When the radio gave the time at the hour, the Ormolu antique was 
  561. exactly 3 minutes slow.
  562.  
  563. "It loses 7 minutes every hour", my old friend told me, as he had done
  564. so many times before.  "No more and no less, but I've gotten used to
  565. it that way."
  566.  
  567. When I spent a second evening with him later that same month, I remarked
  568. on the fact that the clock was dead right by radio time at the hour.
  569. It was rather late in the evening, but Tom assured me that his treasure
  570. had not been adjusted nor fixed since my last visit.
  571.  
  572. What day of the week was the second visit?
  573.  
  574. From "Mathematical Diversions" by Hunter + Madachy
  575.  
  576. ==> arithmetic/clock/day.of.week.s <==
  577. The answer is 17 days and 3 hours later, which would have been a Wednesday.
  578. This is the only other time in the same month when the two would agree at all.
  579.  
  580. In 17 days the slow clock loses 17*24*7 minutes = 2856 minutes,
  581. or 47 hours and 36 minutes.  In 3 hours more it loses 21 minutes, so
  582. it has lost a total of 47 hours and 57 minutes.  Modulo 12 hours, it
  583. has *gained* 3 minutes so as to make up the 3 minutes it was slow on
  584. Sunday.  It is now (fortnight plus 3 days) exactly accurate.
  585.  
  586. ==> arithmetic/clock/thirds.p <==
  587. Do the 3 hands on a clock ever divide the face of the clock into 3
  588. equal segments, i.e. 120 degrees between each hand?       
  589.  
  590. ==> arithmetic/clock/thirds.s <==
  591. First let us assume that our clock has 60 divisions.  We will show that
  592. any time the hour hand and the minute hand are 20 divisions (120 degrees)
  593. apart, the second hand cannot be an integral number of divisions from the
  594. other hands, unless it is straight up (on the minute).
  595.  
  596. Let us use h for hours, m for minutes, and s for seconds.
  597. We will use =n to mean congruent mod n, thus 12 =5 7.
  598.  
  599. We know that m =60 12h, that is, the minute hand moves 12 times as fast
  600. as the hour hand, and wraps around at 60.
  601. We also have s =60 60m. This simplifies to s/60 =1 m, which goes to
  602. s/60 = frac(m) (assuming s is in the range 0 <= s < 60), which goes to
  603. s = 60 frac(m).  Thus, if m is 5.5, s is 30.
  604.  
  605. Now let us assume the minute hand is 20 divisions ahead of the hour hand.
  606. So m =60 h + 20, thus 12h =60 h + 20, 11h =60 20, and, finally,
  607. h =60/11 20/11 (read 'h is congruent mod 60/11 to 20/11').
  608. So all values of m are k + n/11 for some integral k and integral n,
  609. 0 <= n < 11.  s is therefore 60n/11.  If s is to be an integral number of
  610. units from m and h, we must have 60n =11 n.  But 60 and 11 are relatively
  611. prime, so this holds only for n = 0.  But if n = 0, m is integral, so
  612. s is 0.
  613.  
  614. Now assume, instead, that the minute hand is 20 divisions behind the hour hand.
  615. So m =60 h - 20, 12h =60 h - 20, 11h =60 -20, h =60/11 -20/11.
  616. So m is still k + n/11.  Thus s must be 0.
  617.  
  618. But if s is 0, h must be 20 or 40.  But this translates to 4 o'clock or
  619. 8 o'clock, at both of which the minute hand is at 0, along with the second
  620. hand.
  621.  
  622. Thus the 3 hands can never be 120 degrees apart, Q.E.D.
  623.  
  624. ==> arithmetic/consecutive.product.p <==
  625. Prove that the product of three or more consecutive natural numbers cannot be a
  626. perfect square.
  627.  
  628. ==> arithmetic/consecutive.product.s <==
  629. Three consecutive numbers:
  630.   If a and b are relatively prime, and ab is a square,
  631.   then a and b are squares. (This is left as an exercise.)
  632.  
  633.   Suppose (n - 1)n(n + 1) = k^2, where n > 1.  
  634.   Then n(n^2 - 1) = k^2.  But n and (n^2 - 1) are relatively prime.
  635.   Therefore n^2 - 1 is a perfect square, which is a contradiction.
  636.  
  637. Four consecutive numbers:
  638.   n(n + 1)(n + 2)(n + 3) = (n^2 + 3n + 1)^2 - 1
  639.  
  640. Five consecutive numbers:
  641.   Assume the product is a integer square, call it m.
  642.  
  643.   The prime factorization of m must have even numbers of each prime factor.
  644.  
  645.   For each prime factor, p, of m, p >= 5, p^2k must divide one of the
  646. consecutive naturals in the product.  (Otherwise, the difference between two
  647. of the naturals in the product would be a positive multiple of a prime >= 5.
  648. But in this problem, the greatest difference is 4.) So we need only consider
  649. the primes 2 and 3.
  650.  
  651.   Each of the consecutive naturals is one of:
  652.     1)    a perfect square
  653.     2)    2 times a perfect square
  654.     3)    3 times a perfect square
  655.     4)    6 times a perfect square.
  656.  
  657.   By the shoe box principle, two of the five consecutive numbers must fall into
  658. the same category.
  659.  
  660.   If there are two perfect squares, then their difference being less than five
  661. limits their values to be 1 and 4.  (0 is not a natural number, so 0 and 1
  662. and 0 and 4 cannot be the perfect squares.)  But 1*2*3*4*5=120!=x*x where x
  663. is an integer.
  664.  
  665.   If there are two numbers that are 2 times a perfect square, then their
  666. difference being less than five implies that the perfect squares (which are
  667. multiplied by 2) are less than 3 apart, and no two natural squares differ by
  668. only 1 or 2.
  669.  
  670.   A similar argument holds for two numbers which are 3 times a perfect square.
  671.  
  672.   We cannot have the case that two of the 5 consecutive numbers are multiples
  673. (much less square multiples) of 6, since their difference would be >= 6, and
  674. our span of five consecutive numbers is only 4.
  675.  
  676.   Therefore the assumption that m is a perfect square does not hold.
  677.  
  678.   QED.
  679.  
  680. In general the equation:
  681.  
  682. y^2 = x(x+1)(x+2)...(x+n),    n > 3
  683.  
  684. has only the solution corresponding to y = 0.
  685.  
  686. This is a theorem of Rigge [O. Rigge, ``Uber ein diophantisches Problem'',
  687. IX Skan. Math. Kong. Helsingfors (1938)] and Erdos [P. Erdos, ``Note on
  688. products of consecutive integers,'' J. London Math. Soc. #14 (1939),
  689. pages 194-198].
  690.  
  691. A proof can be found on page 276 of [L. Mordell, ``Diophantine
  692. Equations'', Academic Press 1969].
  693.  
  694. ==> arithmetic/consecutive.sums.p <==
  695. Find all series of consecutive positive integers whose sum is exactly 10,000.
  696.  
  697. ==> arithmetic/consecutive.sums.s <==
  698. Generalize to find X (and I) such that
  699.     (X + X+1 + X+2 + ... + X+I) = T
  700. for any integer T.
  701.  
  702. You are asking for all (X,I) s.t. (2X+I)(I+1) = 2T.  The problem is
  703. (very) slightly easier if we don't restrict X to being positive, so
  704. we'll solve this first.
  705.  
  706. Note that 2X+I and I+1 must have different parities, so the answer
  707. to the relaxed question is N = 2*(o_1+1)*(o_2+1)*...*(o_n+1), where
  708. 2T = 2^o_0*3^o_1*...*p_n^o_n (the prime factorization); this is easily
  709. seen to be the number of ways we can break 2T up into two positive
  710. factors of differing parity (with order).
  711.  
  712. In particular, 20000 = 2^5*5^4, hence there are 2*(4+1) = 10 solutions
  713. for T = 10000.  These are (2X+I,I+1):
  714.  
  715. (32*1,5^4)   (32*5,5^3)   (32*5^2,5^2)   (32*5^3,5)   (32*5^4,1)
  716. (5^4,32*1)   (5^3,32*5)   (5^2,32*5^2)   (5,32*5^3)   (1,32*5^4)
  717.  
  718. And they give rise to the solutions (X,I):
  719.  
  720. (-296,624)   (28,124)   (388,24)   (1998,4)     (10000,0)
  721. (297,31)     (-27,179)  (-387,799) (-1997,3999) (-9999,19999)
  722.  
  723. If you require that X>0 note that this is true iff 2X+I > I+1 and
  724. hence the number of solutions to this problem is N/2 (due to the
  725. symmetry of the above ordered pairs).
  726.  
  727. ==> arithmetic/digits/all.ones.p <==
  728. Prove that some multiple of any integer ending in 3 contains all 1s.
  729.  
  730. ==> arithmetic/digits/all.ones.s <==
  731. Let n be our integer; one such desired multiple is then
  732. ( 10^(phi(n))-1 )/9.  All we need is that (n,10) = 1, and
  733. if the last digit is 3 this must be the case.  A different
  734. proof using the pigeonhole principle is to consider the sequence
  735. 1, 11, 111, ..., (10^n - 1)/9.  By previous reasoning we must
  736. have at some point that either some member of our sequence = 0 (mod n)
  737. or else some value (mod n) is duplicated.  Assume the latter, with
  738. x_a and x_b, x_b>x_a,  possesing the duplicated remainders.  We then
  739. have that x_b - x-a = 0 (mod n).  Let m be the highest power of 10
  740. dividing x_b - x_a.  Now since (10,n) = 1, we can divide by 10^m and
  741. get that (x_b - x_a)/10^m = 0 (n).  But (x_b - x_a)/10^m is a number
  742. containing only the digit 1.
  743.  
  744. Q.E.D.
  745.  
  746. ==> arithmetic/digits/arabian.p <==
  747. What is the Arabian Nights factorial, the number x such that x! has 1001
  748. digits?  How about the prime x such that x! has exactly 1001 zeroes on
  749. the tail end.  (Bonus question, what is the 'rightmost' non-zero digit in x!?)
  750.  
  751. ==> arithmetic/digits/arabian.s <==
  752. The first answer is 450!.
  753.  
  754. Determining the number of zeroes at the end of x! is relatively easy once
  755. you realize that each such zero comes from a factor of 10 in the product
  756.  
  757.    1 * 2 * 3 * ... * x
  758.  
  759. Each factor of 10, in turn, comes from a factor of 5 and a factor of 2.
  760. Since there are many more factors of 2 than factors of 5, the number of 5s
  761. determines the number of zeroes at the end of the factorial.
  762.  
  763. The number of 5s in the set of numbers 1 .. x (and therefore the number
  764. of zeroes at the end of x!) is:
  765.  
  766.   z(x) = int(x/5) + int(x/25) + int(x/125) + int(x/625) + ...
  767.  
  768. This series terminates when the powers of 5 exceed x.
  769.  
  770. I know of no simple way to invert the above formula (i.e., to find x for
  771. a given z(x)), but I can approximate it by noting that, except for the "int"
  772. function,
  773.  
  774.    5*z(x) - x = z(x)
  775.  
  776. which gives:
  777.  
  778.    x = 4*z(x) (approximately).
  779.  
  780. The given problem asked, "For what prime x is z(x)=1001".  By the above forumla,
  781. this is approximately 4*1001=4004.  However, 4004! has only
  782.  
  783.   800 + 160 + 32 + 6 + 1 = 999 zeroes at the end of it.
  784.  
  785. The numbers 4005! through 4009! all have 1000 zeroes at their end and
  786. the numbers 4010! through 4014! all have 1001 zeroes at their end.
  787.  
  788. Since the problem asked for a prime x, and 4011 = 3*7*191, the only solution
  789. is x=4013.
  790.  
  791. The problem of determining the rightmost nonzero digit in x! is somewhat more
  792. difficult.  If we took the numbers 1, 2, ... , x and removed all factors of 5
  793. (and an equal number of factors of 2), the remaining numbers multiplied
  794. together modulo 10 would be the answer.  Note that since there are still many
  795. factors of 2 left, the rightmost nonzero digit must be 2, 4, 6, or 8 (x > 1).
  796.  
  797. Letting r(x) be the rightmost nonzero digit in x!, an expression for r(x) is:
  798.  
  799.   r(x) = (r(int(x/5)) * w * r(x mod 10)) mod 10, x >= 10.
  800.  
  801. where w is 4 if int(x/10) is odd and 6 if it is even.
  802.  
  803. The values of r(x) for 0 <= x <= 9 are 1, 1, 2, 6, 4, 2, 2, 4, 2, and 8.
  804.  
  805. The way to see this is true is to take the numbers 1, 2, ..., x in groups
  806. of 10.  In each group, remove 2 factors of 10.  For example, from the
  807. set 1, 2, ..., 10, choose a factor of 2 from 2 and 6 and a factor of 5 from
  808. 5 and 10.  This leaves 1, 1, 3, 4, 1, 3, 7, 8, 9, 2.  Next, separate all the
  809. factors that came from multiples of 5.  The rightmost nonzero digit of x!
  810. can now (hopefully) be seen to be:
  811.  
  812.   r(x) = (r(int(x/5)) * w * r(x mod 10)) mod 10
  813.  
  814. where w is the rightmost digit in the number formed by multiplying the numbers
  815. 1, 2, 3, ..., 10*int(x/10) after the factors of 10 and the factors left over
  816. by the multiples of 5 have been removed.  In the example with x = 10, this
  817. would be (1 * 1 * 3 * 4 * 3 * 7 * 8 * 9) mod 10 = 4.  The "r(x mod 10)" term
  818. takes care of the numbers from 10*int(x/10)+1 up to x.
  819.  
  820. The "w" term can be seen to be 4 or 6 depending on whether int(x/10) is odd or
  821. even since, after removing 10*n+5 and 10*n+10 and a factor of 2 each from
  822. 10*n+2 and 10*n+6 from the group of numbers 10*n+1 through 10*n+10, the
  823. remaining factors (mod 10) always equals 4 and 4^t mod 10 = 4 if t is odd and
  824. 6 when t is even (t != 0).
  825.  
  826. So, finally, the rightmost nonzero digit in 4013! is found as follows:
  827.  
  828.   r(4013) = (r(802) * 4 * 6) mod 10
  829.   r(802)  = (r(160) * 6 * 2) mod 10
  830.   r(160)  = (r(32)  * 6 * 1) mod 10
  831.   r(32)   = (r(6)   * 4 * 2) mod 10
  832.  
  833. Using a table of r(x) for 0 <= x <= 9, r(6) = 2.  Then,
  834.  
  835.   r(32)   = (2 * 4 * 2) mod 10 = 6
  836.   r(160)  = (6 * 6 * 1) mod 10 = 6
  837.   r(802)  = (6 * 6 * 2) mod 10 = 2
  838.   r(4013) = (2 * 4 * 6) mod 10 = 8
  839.  
  840. Thus, the rightmost nonzero digit in 4013! is 8.
  841.  
  842. ==> arithmetic/digits/circular.p <==
  843. What 6 digit number, with 6 different digits, when multiplied by all integers
  844. up to 6, circulates its digits through all 6 possible positions, as follows:
  845. ABCDEF * 1 = ABCDEF
  846. ABCDEF * 3 = BCDEFA
  847. ABCDEF * 2 = CDEFAB
  848. ABCDEF * 6 = DEFABC
  849. ABCDEF * 4 = EFABCD
  850. ABCDEF * 5 = FABCDE
  851.  
  852. ==> arithmetic/digits/circular.s <==
  853. ABCDEF=142857 (the digits of the expansion of 1/7).
  854.  
  855. ==> arithmetic/digits/divisible.p <==
  856. Find the least number using 0-9 exactly once that is evenly divisible by each
  857. of these digits?
  858.  
  859. ==> arithmetic/digits/divisible.s <==
  860. Since the sum of the digits is 45, any permutation of the digits gives a
  861. multiple of 9.  To get a multiple of both 2 and 5, the last digit must
  862. be 0, and thus to get a multiple of 8 (and 4), the tens digit must be
  863. even, and the hundreds digit must be odd if the tens digit is 2 or 6,
  864. and even otherwise.  The number will also be divisible by 6, since it is
  865. divisible by 2 and 3, so 7 is all we need to check.  First, we will look
  866. for a number whose first five digits are 12345; now, 1234500000 has a
  867. remainder of 6 when divided by 7, so we have to arrange the remaining
  868. digits to get a remainder of 1.  The possible arrangements, in
  869. increasing order, are
  870.  
  871. 78960, remainder 0
  872. 79680, remainder 6
  873. 87960, remainder 5
  874. 89760, remainder 6
  875. 97680, remainder 2
  876. 98760, remainder 4
  877.  
  878. That didn't work, so try numbers starting with 12346; this is impossible
  879. because the tens digit must be 8, and the hundreds digit cannot be even.
  880. Now try 12347, and 1234700000 has remainder 2.  The last five digits can
  881. be
  882.  
  883. 58960, remainder 6
  884. 59680, remainder 5, so this works, and the number is
  885.  
  886. 1234759680.
  887.  
  888. ==> arithmetic/digits/equations/123456789.p <==
  889. In how many ways can "." be replaced with "+", "-", or "" (concatenate) in
  890. .1.2.3.4.5.6.7.8.9=1 to form a correct equation?
  891.  
  892. ==> arithmetic/digits/equations/123456789.s <==
  893.  1-2 3+4 5+6 7-8 9 = 1
  894. +1-2 3+4 5+6 7-8 9 = 1
  895.  1+2 3+4-5+6 7-8 9 = 1
  896. +1+2 3+4-5+6 7-8 9 = 1
  897. -1+2 3-4+5+6 7-8 9 = 1
  898.  1+2 3-4 5-6 7+8 9 = 1
  899. +1+2 3-4 5-6 7+8 9 = 1
  900.  1-2 3-4+5-6 7+8 9 = 1
  901. +1-2 3-4+5-6 7+8 9 = 1
  902.  1-2-3-4 5+6 7-8-9 = 1
  903. +1-2-3-4 5+6 7-8-9 = 1
  904.  1+2-3 4+5 6-7-8-9 = 1
  905. +1+2-3 4+5 6-7-8-9 = 1
  906. -1+2 3+4+5-6-7-8-9 = 1
  907. -1 2+3 4-5-6+7-8-9 = 1
  908.  1+2+3+4-5+6+7-8-9 = 1
  909. +1+2+3+4-5+6+7-8-9 = 1
  910. -1+2+3-4+5+6+7-8-9 = 1
  911.  1-2-3+4+5+6+7-8-9 = 1
  912. +1-2-3+4+5+6+7-8-9 = 1
  913.  1+2 3+4 5-6 7+8-9 = 1
  914. +1+2 3+4 5-6 7+8-9 = 1
  915.  1+2 3-4-5-6-7+8-9 = 1
  916. +1+2 3-4-5-6-7+8-9 = 1
  917.  1+2+3+4+5-6-7+8-9 = 1
  918. +1+2+3+4+5-6-7+8-9 = 1
  919. -1+2+3+4-5+6-7+8-9 = 1
  920.  1-2+3-4+5+6-7+8-9 = 1
  921. +1-2+3-4+5+6-7+8-9 = 1
  922. -1-2-3+4+5+6-7+8-9 = 1
  923.  1-2+3+4-5-6+7+8-9 = 1
  924. +1-2+3+4-5-6+7+8-9 = 1
  925.  1+2-3-4+5-6+7+8-9 = 1
  926. +1+2-3-4+5-6+7+8-9 = 1
  927. -1-2+3-4+5-6+7+8-9 = 1
  928. -1+2-3-4-5+6+7+8-9 = 1
  929. -1+2 3+4 5-6 7-8+9 = 1
  930.  1-2 3-4 5+6 7-8+9 = 1
  931. +1-2 3-4 5+6 7-8+9 = 1
  932. -1+2 3-4-5-6-7-8+9 = 1
  933. -1+2+3+4+5-6-7-8+9 = 1
  934.  1-2+3+4-5+6-7-8+9 = 1
  935. +1-2+3+4-5+6-7-8+9 = 1
  936.  1+2-3-4+5+6-7-8+9 = 1
  937. +1+2-3-4+5+6-7-8+9 = 1
  938. -1-2+3-4+5+6-7-8+9 = 1
  939.  1+2-3+4-5-6+7-8+9 = 1
  940. +1+2-3+4-5-6+7-8+9 = 1
  941. -1-2+3+4-5-6+7-8+9 = 1
  942. -1+2-3-4+5-6+7-8+9 = 1
  943.  1-2-3-4-5+6+7-8+9 = 1
  944. +1-2-3-4-5+6+7-8+9 = 1
  945.  1-2 3+4+5+6+7-8+9 = 1
  946. +1-2 3+4+5+6+7-8+9 = 1
  947.  1+2+3+4 5-6 7+8+9 = 1
  948. +1+2+3+4 5-6 7+8+9 = 1
  949.  1 2+3 4+5-6 7+8+9 = 1
  950. +1 2+3 4+5-6 7+8+9 = 1
  951.  1+2+3-4-5-6-7+8+9 = 1
  952. +1+2+3-4-5-6-7+8+9 = 1
  953. -1+2-3+4-5-6-7+8+9 = 1
  954.  1-2-3-4+5-6-7+8+9 = 1
  955. +1-2-3-4+5-6-7+8+9 = 1
  956. -1-2-3-4-5+6-7+8+9 = 1
  957. -1-2 3+4+5+6-7+8+9 = 1
  958.  1-2+3 4-5 6+7+8+9 = 1
  959. +1-2+3 4-5 6+7+8+9 = 1
  960.  1 2-3 4+5-6+7+8+9 = 1
  961. +1 2-3 4+5-6+7+8+9 = 1
  962. Total solutions  = 69
  963.  
  964. 69/19683 = 0.35 %
  965.  
  966. for those who care (it's not very elegant but it did the trick):
  967.  
  968. #include <stdio.h>
  969. #include <math.h>
  970.  
  971. main (argc,argv)
  972.      int argc;
  973.      char *argv[];
  974. {
  975.   int sresult, result, operator[10],thisop;
  976.   char buf[256],ops[3];
  977.   int i,j,tot=0,temp;
  978.   
  979.   ops[0] = ' ';
  980.   ops[1] = '-';
  981.   ops[2] = '+';
  982.  
  983.   for (i=1; i<10; i++) operator[i] = 0;
  984.   
  985.   for (j=0; j < 19683; j++) {
  986.     result = 0;
  987.     sresult = 0;
  988.     thisop = 1;
  989.     for (i=1; i<10; i++) {
  990.       switch (operator[i]) {
  991.       case 0:
  992.     sresult = sresult * 10 + i;
  993.     break;
  994.       case 1:
  995.     result = result + sresult * thisop;
  996.     sresult = i;
  997.     thisop = -1;
  998.     break;
  999.       case 2:
  1000.     result = result + sresult * thisop;
  1001.     sresult = i;
  1002.     thisop = 1;
  1003.     break;
  1004.       }
  1005.     }
  1006.   
  1007.     result  = result + sresult * thisop;
  1008.     if (result == 1) {
  1009.       tot++;
  1010.       for  (i=1;i<10;i++) 
  1011.     printf("%c%d",ops[operator[i]],i);
  1012.       printf(" = %d\n",result);
  1013.     }
  1014.     temp = 0;
  1015.     operator[1] += 1;
  1016.     for (i=1;i<10;i++) {
  1017.       operator[i] += temp;
  1018.       if (operator[i] > 2) { operator[i] = 0; temp = 1;}
  1019.       else temp = 0;
  1020.     }
  1021.   
  1022.   }
  1023.   
  1024.   printf("Total solutions  = %d\n" , tot);
  1025. }
  1026.  
  1027. cwren@media.mit.edu (Christopher Wren)
  1028.  
  1029. ==> arithmetic/digits/equations/1992.p <==
  1030. 1 = -1+9-9+2.  Extend this list to 2 - 100 on the left side of the equals sign.
  1031.  
  1032. ==> arithmetic/digits/equations/1992.s <==
  1033. 1 = -1+9-9+2
  1034. 2 = 1*9-9+2
  1035. 3 = 1+9-9+2
  1036. 4 = 1+9/9+2
  1037. 5 = 1+9-sqrt(9)-2
  1038. 6 = 1^9+sqrt(9)+2
  1039. 7 = -1+sqrt(9)+sqrt(9)+2
  1040. 8 = 19-9-2
  1041. 9 = (1/9)*9^2
  1042. 10= 1+(9+9)/2
  1043. 11= 1+9+sqrt(9)-2
  1044. 12= 19-9+2
  1045. 13= (1+sqrt(9))!-9-2
  1046. 14= 1+9+sqrt(9)!-2
  1047. 15= -1+9+9-2
  1048. 16= -1+9+sqrt(9)!+2
  1049. 17= 1+9+9-2
  1050. 18= 1+9+sqrt(9)!+2
  1051. 19= -1+9+9+2
  1052. 20= (19-9)*2
  1053. 21= 1+9+9+2
  1054. 22= (-1+sqrt(9))*(9-2)
  1055. 23= (1+sqrt(9))!-sqrt(9)+2
  1056. 24= -1+9*sqrt(9)-2
  1057. 25= 1*9*sqrt(9)-2
  1058. 26= 19+9-2
  1059. 27= 1*9+9*2
  1060. 28= 1+9+9*2
  1061. 29= 1*9*sqrt(9)+2
  1062. 30= 19+9+2
  1063. 31= (1+sqrt(9))!+9-2
  1064. 32= -1+sqrt(9)*(9+2)
  1065. 33= 1*sqrt(9)*(9+2)
  1066. 34= (-1+9+9)*2
  1067. 35= -1+(9+9)*2
  1068. 36= 1^9*sqrt(9)!^2
  1069. 37= 19+9*2
  1070. 38= 1*sqrt(9)!*sqrt(9)!+2
  1071. 39= 1+sqrt(9)!*sqrt(9)!+2
  1072. 40= (1+sqrt(9)!)*sqrt(9)!-2
  1073. 41= -1+sqrt(9)!*(9-2)
  1074. 42= (1+sqrt(9))!+9*2
  1075. 43= 1+sqrt(9)!*(9-2)
  1076. 44= -1+9*(sqrt(9)+2)
  1077. 45= 1*9*(sqrt(9)+2)
  1078. 46= 1+9*(sqrt(9)+2)
  1079. 47= (-1+sqrt(9)!)*9+2
  1080. 48= 1*sqrt(9)!*(sqrt(9)!+2)
  1081. 49= (1+sqrt(9)!)*(9-2)
  1082. 50= (-1+9)*sqrt(9)!+2
  1083. 51= -1+9*sqrt(9)!-2
  1084. 52= 1*9*sqrt(9)!-2
  1085. 53= -1+9*sqrt(9)*2
  1086. 54= 1*9*sqrt(9)*2
  1087. 55= 1+9*sqrt(9)*2
  1088. 56= 1*9*sqrt(9)!+2
  1089. 57= 1+9*sqrt(9)!+2
  1090. 58= (1+9)*sqrt(9)!-2
  1091. 59= 19*sqrt(9)+2
  1092. 60= (1+9)*sqrt(9)*2
  1093. 61= (1+sqrt(9)!)*9-2
  1094. 62= -1+9*(9-2)
  1095. 63= 1*9*(9-2)
  1096. 64= 1+9*(9-2)
  1097. 65= (1+sqrt(9)!)*9+2
  1098. 66= 1*sqrt(9)!*(9+2)
  1099. 67= 1+sqrt(9)!*(9+2)
  1100. 68= -(1+sqrt(9))!+92
  1101. 69= (1+sqrt(9))!+(9/.2)
  1102. 70= (1+9)*(9-2)
  1103. 71= -1-9+9^2
  1104. 72= (1+sqrt(9))*9*2
  1105. 73= -19+92
  1106. 74= (-1+9)*9+2
  1107. 75= -1*sqrt(9)!+9^2
  1108. 76= 1-sqrt(9)!+9^2
  1109. 77= (1+sqrt(9)!)*(9+2)
  1110. 78= -1+9*9-2
  1111. 79= 1*9*9-2
  1112. 80= 1+9*9-2
  1113. 81= 1*9*sqrt(9)^2
  1114. 82= -1+9*9+2
  1115. 83= 1*9*9+2
  1116. 84= 1+9*9+2
  1117. 85= -1-sqrt(9)!+92
  1118. 86= -1*sqrt(9)!+92
  1119. 87= 1-sqrt(9)!+92
  1120. 88= (1+9)*9-2
  1121. 89= -1*sqrt(9)+92
  1122. 90= 1-sqrt(9)+92
  1123. 91= -1^9+92
  1124. 92= (1+9)*9+2
  1125. 93= 1^9+92
  1126. 94= -1+sqrt(9)+92
  1127. 95= 19*(sqrt(9)+2)
  1128. 96= -1+99-2
  1129. 97= 1*99-2
  1130. 98= 1+99-2
  1131. 99= 1*9*(9+2)
  1132. 100= -1+99+2
  1133.  
  1134. ==> arithmetic/digits/equations/383.p <==
  1135. Make 383 out of 1,2,25,50,75,100 using +,-,*,/.
  1136.  
  1137. ==> arithmetic/digits/equations/383.s <==
  1138. You can get 383 with ((2+50)/25+1)*100+75.
  1139.  
  1140. Of course, if you expect / as in C, the above expression is just 375.
  1141. But then you can get 383 with (25*50-100)/(1+2).  Pity there's no way
  1142. to use the 75.
  1143.  
  1144. If we had a language that rounded instead of truncating, we could use
  1145. ((1+75+100)*50)/(25-2) or (2*75*(25+100))/(50-1).
  1146.  
  1147. I imagine your problem lies in not dividing things that aren't
  1148. divisible.
  1149.  
  1150. Dan Hoey
  1151. Hoey@AIC.NRL.Navy.Mil
  1152.  
  1153. ==> arithmetic/digits/extreme.products.p <==
  1154. What are the extremal products of three three-digit numbers using digits 1-9?
  1155.  
  1156. ==> arithmetic/digits/extreme.products.s <==
  1157. There is a simple procedure which applies to these types of problems (and
  1158. which can be proven with help from the arithmetic-geometric inequality).
  1159.  
  1160. For the first part we use the "first large then equal" procedure.
  1161. This means that are three numbers will be 7**, 8**, and 9**.  Now
  1162. the digits 4,5,6 get distributed so as to make our three number as
  1163. close to each other as possible, i.e. 76*, 85*, 94*.  The same goes
  1164. for the remaining three digits, and we get 763, 852, 941.
  1165.  
  1166. For the second part we use the "first small then different" procedure.
  1167. Our three numbers will be of the form 1**, 2**, 3**.  We now place
  1168. the three digits so as to make our three numbers as unequal as possible;
  1169. this gives 14*, 25*, 36*.  Finishing, we get 147, 258, 369.
  1170.  
  1171. Now, *prove* that these procedures work for generalizations of this
  1172. problem.
  1173.  
  1174. ==> arithmetic/digits/googol.p <==
  1175. What digits does googol! start with?
  1176.  
  1177. ==> arithmetic/digits/googol.s <==
  1178. I'm not sure how to calculate the first googol of digits of log10(e), but
  1179. here's the first 150(approximately) of them...
  1180.  
  1181. 0.43429448190325182765112891891660508229439700580366656611445378316586464920
  1182. 8870774729224949338431748318706106744766303733641679287158963906569221064663
  1183.  
  1184. We need to deal with the digits immediately after the decimal point in
  1185. googol*log10(e), which are  .187061
  1186.  
  1187. frac[log(googol!)] = frac[halflog2pi + 50 + googol(100-log10(e))]
  1188.  = frac{halflog2pi + frac[googol(100-log10(e))]}
  1189.  = frac[.399090 + (1- .187061)]
  1190.  = .212029
  1191.  
  1192. 10 ** .212029 = 1.629405
  1193.  
  1194. Which means that googol! starts with 1629
  1195.  
  1196. ==> arithmetic/digits/labels.p <==
  1197. You have an arbitrary number of model kits (which you assemble for
  1198. fun and profit).  Each kit comes with twenty (20) stickers, two of which
  1199. are labeled "0", two are labeled "1", ..., two are labeled "9".
  1200. You decide to stick a serial number on each model you assemble starting
  1201. with one.  What is the first number you cannot stick.  You may stockpile
  1202. unused numbers on already assembled models, but you may not crack open
  1203. a new model to get at its stickers.  You complete assembling the current
  1204. model before starting the next.
  1205.  
  1206. ==> arithmetic/digits/labels.s <==
  1207. The method I used for this problem involved first coming up with a
  1208. formula that says how many times a digit has been used in all n models.
  1209.  
  1210. n = k*10^i + m for some k,m with 0 <k <10, m < 10^i
  1211. f(d,n) = (number of d's used getting to k*10^i from digits 0 to (i-1)) +
  1212.     (number of d's used by #'s 10^i to n from digit i) + f(d,m)
  1213. f(d,n) = i*k*10^(i-1) + (if (d < k) 10^i else if (d == k) m+1 else 0) + f(d,m)
  1214.  
  1215. This doesn't count 0's, which should be ok as they are not used as often
  1216. as other digits.  From the formula, it is clear that f(1,n) is never
  1217. less than f(d,n) for 1<d<10.
  1218. So I just calculated f(1,n) for various n (with some help from bc).
  1219.  
  1220. I quickly discovered that for n = 2*10^15, f(1,n) = 2*n.  After further
  1221. trials I determined that for n = 1999919999999981, f(1,n) = 2*n + 1. 
  1222. This appears to be the smallest n with f(1,n) > 2*n.
  1223.  
  1224. ==> arithmetic/digits/nine.digits.p <==
  1225. Form a number using 0-9 once with its first n digits divisible by n.
  1226.  
  1227. ==> arithmetic/digits/nine.digits.s <==
  1228. First, reduce the sample set. For each digit of ABCDEFGHI, such that the last
  1229. digit, (current digit), is the same as a multiple of N :
  1230.  
  1231. A: Any number 1-9
  1232. B: Even numbers 2,4,6,8 (divisible by 2).
  1233. C: Any number 1-9 (21,12,3,24,15,6,27,18,9).
  1234. D: Even numbers 2,4,6,8 (divisible by 4, every other even).
  1235. E: 5 (divisible by 5 and 0 not allowed).
  1236. F: Even numbers (12,24,6,18)
  1237. G: Any number 1-9 (21,42,63,14,35,56,7,28,49).
  1238. H: Even numbers (32,24,16,8)
  1239. I: Any number 1-9 (81,72,63,54,45,36,27,18,9)
  1240.  
  1241. Since E must be 5, I can eliminate it everywhere else.
  1242. Since I will use up all the even digits, (2,4,6,8) filling in those spots
  1243.    that must be even. Any number becomes all odds, except 5.
  1244.  
  1245. A: 1,3,7,9
  1246. B: 2,4,6,8
  1247. C: 1,3,7,9
  1248. D: 2,4,6,8
  1249. E: 5
  1250. F: 2,4,6,8
  1251. G: 1,3,7,9
  1252. H: 2,4,6,8
  1253. I: 1,3,7,9
  1254.  
  1255. We have that 2C+D=0 (mod 4), and since C is odd,
  1256. this implies that D is 2 or 6; similarly we find that H is 2 or 6 ==>
  1257. {B,F} = {4,8}.  D+5+F=0 (mod 3) ==> if D=2 then F=8, if D=6 then F=4.
  1258.  
  1259. We have two cases.
  1260.  
  1261. Assume our number is of the form A4C258G6I0.  Now the case n=8 ==>
  1262. G=1,9; case n=3 ==> A+1+C=0 (mod 3) ==> {A,C}={1,7} ==> G=9, I=3.
  1263. The two numbers remaining fail for n=7.
  1264.  
  1265. Assume our number is of the form A8C654G2I0.  The case n=8 ==> G=3,7.
  1266. If G=3, we need to check to see which of 1896543, 9816543, 7896543, 
  1267. and 9876543 are divisible by 7; none are.
  1268.  
  1269. If G=7, we need to check to see which of 1896547, 9816547, 1836547,
  1270. and 3816547 are divisible by 7; only the last one is, which yields
  1271. the solution 3816547290.
  1272.  
  1273. ==> arithmetic/digits/palindrome.p <==
  1274. Does the series formed by adding a number to its reversal always end in
  1275. a palindrome?
  1276.  
  1277. ==> arithmetic/digits/palindrome.s <==
  1278. This is not known.
  1279.  
  1280. If you start with 196, after 9480000 iterations you get a 3924257-digit
  1281. non-palindromic number.  However, there is no known proof that you will
  1282. never get a palindrome.
  1283.  
  1284. The statement is provably false for binary numbers. Roland Sprague has
  1285. shown that 10110 starts a series that never goes palindromic.
  1286.  
  1287. ==> arithmetic/digits/palintiples.p <==
  1288. Find all numbers that are multiples of their reversals.
  1289.  
  1290. ==> arithmetic/digits/palintiples.s <==
  1291. We are asked to find numbers that are integer multiples of their
  1292. reversals, which I call palintiples.  Of course, all the palindromic
  1293. numbers are a trivial example, but if we disregard the unit multiples,
  1294. the field is narrowed considerably.
  1295.  
  1296. Rouse Ball (_Mathematical_recreations_and_essays_) originated the
  1297. problem, and G. H. Hardy (_A_mathematician's_apology_) used the result
  1298. that 9801 and 8712 are the only four-digit palintiples as an example
  1299. of a theorem that is not ``serious''.  Martin Beech (_The_mathema-
  1300. tical_gazette_, Vol 74, #467, pp 50-51, March '90) observed that
  1301. 989*01 and 879*12 are palintiples, an observation he ``confirmed'' on
  1302. a hand calculator, and conjectured that these are all that exist.
  1303.  
  1304. I confirm that Beech's numbers are palintiples, I will show that they
  1305. are not all of the palintiples.  I will show that the palintiples do
  1306. not form a regular language.  And then I will prove that I have found
  1307. all the palintiples, by describing the them with a generalized form
  1308. of regular expression.  The results become more interesting in other
  1309. bases.
  1310.  
  1311. First, I have a more reasonable method of confirming that these
  1312. numbers are palintiples:
  1313.  
  1314.     Proof:  First, letting "9*" and "0*" refer an arbitrary string of
  1315.     nines and a string of zeroes of the same length, I note that
  1316.  
  1317.         879*12 = 879*00 + 12 = (880*00 - 100) + 12 = 880*00 - 88
  1318.         219*78 = 219*00 + 78 = (220*00 - 100) + 78 = 220*00 - 22
  1319.  
  1320.         989*01 = 989*00 +  1 = (990*00 - 100) +  1 = 990*00 - 99
  1321.         109*89 = 109*00 + 89 = (110*00 - 100) + 89 = 110*00 - 11
  1322.  
  1323.     It is obvious that 4x(220*00 - 22) = 880*00 - 88 and that
  1324.     9x(110*00 - 11) = 990*00 - 99.  QED.
  1325.  
  1326. Now, to show that these palintiples are not all that exist, let us
  1327. take the (infinite) language L[4] = (879*12 + 0*), and let Pal(L[4])
  1328. refer to the set of palindromes over the alphabet L[4].  It is
  1329. immediate that the numbers in Pal(L[4]) are palintiples.  For
  1330. instance,
  1331.  
  1332.           8712 000 87912 879999912 879999912 87912 000 8712
  1333.     = 4 x 2178 000 21978 219999978 219999978 21978 000 2178
  1334.  
  1335. (where I have inserted spaces to enhance readability) is a palintiple.
  1336. Similarly, taking L[9] = (989*01 + 0*), the numbers in Pal(L[9]) are
  1337. palintiples.  We exclude numbers starting with zeroes.
  1338.  
  1339. The reason these do not form a regular language is that the
  1340. sub-palintiples on the left end of the number must be the same (in
  1341. reverse order) as the sub-palintiples on the right end of the number:
  1342.  
  1343.          8712 8712 87999912 = 4 x 2178 2178 21999978
  1344.  
  1345. is not a palintiple, because 8712 8712 87999912 is not the reverse of
  1346. 2178 2178 21999978.  The pumping lemma can be used to prove that
  1347. Pal(L[4])+Pal(L[9]) is not a regular language, just as in the familiar
  1348. proof that the palindromes over a non-singleton alphabet do not form a
  1349. regular language.
  1350.  
  1351. Now to characterize all the palintiples, let N be a palintiple,
  1352. N=CxR(N), where R(.) signifies reversal, and C>1 is an integer.  (I
  1353. use "x" for multiplication, to avoid confusion with the Kleene star
  1354. "*", which signifies the concatenated closure.)  If D is a digit of N,
  1355. let D' refer to the corresponding digit of R(N).  Since N=CxR(N),
  1356. D+10T = CxD'+S, where S is the carry in to the position occupied by D'
  1357. when R(N) is multiplied by C, and T is the carry out of that position.
  1358. Similarly, D'+10T'=CxD+S', where S', T' are carries in and out of the
  1359. position occupied by D when R(N) is multiplied by C.
  1360.  
  1361. Since D and D' are so closely related, I will use the symbol D:D' to
  1362. refer to a digit D on the left side of a string with a corresponding
  1363. digit D' on the right side of the string.  More formally, an
  1364. expression "x[1]:y[1] x[2]:y[2] ... x[n]:y[n] w" will refer to a
  1365. string "x[1] x[2] ... x[n] w y[n] ... y[2] y[1]", where the x[i] and
  1366. y[i] are digits and w is a string of zero or one digits.  So 989901
  1367. may be written as 9:1 8:0 9:9 and 87912 may be written as 8:2 7:1 9.
  1368. Thus Pal(L[4])+Pal(L[9]) (omitting numbers with leading zeroes) can be
  1369. represented as
  1370.  
  1371.             (8:2 7:1 9:9* 1:7 2:8 0:0*)*
  1372.               (0:0* + 0 + 8:2 7:1 ( 9:9* + 9:9* 9))
  1373.           + (9:1 8:0 9:9* 0:8 1:9 0:0*)*
  1374.               (0:0* + 0 + 9:1 8:0 ( 9:9* + 9:9* 9)).      (1)
  1375.  
  1376. For each pair of digits D:D', there are a very limited--and often
  1377. empty--set of quadruples S,T,S',T' of digits that satisfy the
  1378. equations
  1379.  
  1380.                     D +10T =CxD'+S
  1381.                     D'+10T'=CxD +S',                      (2)
  1382.  
  1383. yet such a quadruple must exist for "D:D'" to appear in a palintiple
  1384. with multiplier C.  Furthermore, the S and T' of one D:D' must be T
  1385. and S', respectively, of the next pair of digits that appear.  This
  1386. enables us to construct a finite state machine to recognize those
  1387. palintiples.  The states [X#Y] refer to a pair of carries in D and D',
  1388. and we allow a transition from state [T#S'] to state [S#T'] on input
  1389. symbol D:D' exactly when equations (2) are satisfied.  Special
  1390. transitions for a single-digit input symbol (the central digit of
  1391. odd-length palintiples) and the criteria for the initial and the
  1392. accepting states are left as exercises.  The finite state machines
  1393. thus formed are
  1394.  
  1395.    State         Symbol  New     Symbol  New      Symbol   New
  1396.         Accept?         State           State             State
  1397.  
  1398. --> [0#0]  Y       8:2  [0#3]      0:0  [0#0]         0   [A]
  1399.     [0#3]  N       7:1  [3#3]
  1400.     [3#3]  Y       1:7  [3#0]      9:9  [3#3]         9   [A]
  1401.     [3#0]  N       2:8  [0#0]
  1402.      [A]   Y
  1403.  
  1404. for constant C=4, and
  1405.  
  1406.    State         Symbol  New     Symbol  New      Symbol   New
  1407.         Accept?         State           State             State
  1408.  
  1409. --> [0#0]  Y       1:9  [0#8]      0:0  [0#0]         0   [A]
  1410.     [0#8]  N       8:0  [8#8]
  1411.     [8#8]  Y       0:8  [8#0]      9:9  [8#8]         9   [A]
  1412.     [8#0]  N       9:1  [0#0]
  1413.      [A]   Y
  1414.  
  1415. for constant C=9, and the finite state machines for other constants
  1416. accept only strings of zeroes.  It is not hard to verify that the
  1417. proposed regular expression (1) represents the union of the languages
  1418. accepted by these machines, omitting the empty string and strings
  1419. beginning with zero.
  1420.  
  1421. I have written a computer program that constructs finite state
  1422. machines for recognizing palintiples for various bases and constants.
  1423. I found that base 10 is actually an unusually boring base for this
  1424. problem.  For instance, the machine for base 8, constant C=5 is
  1425.  
  1426.    State         Symbol  New     Symbol  New      Symbol  New
  1427.         Accept?         State           State            State
  1428.  
  1429. --> [0#0]  Y       0:0  [0#0]      5:1  [0#3]         0  [A]
  1430.     [0#3]  N       1:0  [1#1]      6:1  [1#4]
  1431.     [1#1]  Y       0:1  [3#0]      5:2  [3#3]
  1432.     [3#0]  N       1:5  [0#0]      6:6  [0#3]         6  [A]
  1433.     [3#3]  Y       2:5  [1#1]      7:6  [1#4]
  1434.     [1#4]  N       1:1  [4#1]      6:2  [4#4]         1  [A]
  1435.     [4#4]  Y       2:6  [4#1]      7:7  [4#4]         7  [A]
  1436.     [4#1]  N       1:6  [3#0]      6:7  [3#3]
  1437.      [A]   Y
  1438.  
  1439. for which I invite masochists to write the regular expression.  If
  1440. anyone wants more, I should remark that the base 29 machine for
  1441. constant C=18 has 71 states!
  1442.  
  1443. By the way, I did not find any way of predicting the size or form of
  1444. the machines for the various bases, except that the machines for C=B-1
  1445. all seem to be isomorphic to each other.  If anyone investigates the
  1446. general behavior, I would be most happy to hear about it.
  1447.  
  1448. Dan Hoey
  1449. Hoey@AIC.NRL.Navy.Mil
  1450. May, 1992
  1451. [ A preliminary version of this message appeared in April, 1991. ]
  1452. ================================================================
  1453. Dan
  1454.  
  1455.  
  1456.  
  1457. ==> arithmetic/digits/power.two.p <==
  1458. Prove that for any 9-digit number (base 10) there is an integral power
  1459. of 2 whose first 9 digits are that number.
  1460.  
  1461. ==> arithmetic/digits/power.two.s <==
  1462. Let v = log to base 10 of 2.
  1463. Then v is irrational.
  1464.  
  1465. Let w = log to base 10 of these 9 digits.
  1466.  
  1467. Since v is irrational, given epsilon > 0, there exists some natural number 
  1468. n such that
  1469.  
  1470.    {w} < {nv} < {w} + epsilon
  1471.  
  1472. ({x} is the fractional part of x.)  Let us pick n for when 
  1473.  
  1474.    epsilon = log 1.00000000000000000000001.
  1475.  
  1476. Then 2^n does the job.
  1477.  
  1478. ==> arithmetic/digits/prime/101.p <==
  1479. How many primes are in the sequence 101, 10101, 1010101, ...?
  1480.  
  1481. ==> arithmetic/digits/prime/101.s <==
  1482. Note that the sequence
  1483. 101 , 10101, 1010101, ....
  1484. can be viewed as 
  1485. 100**1 +1, 100**2 + 100**1 + 1, 100**3 + 100**2 + 100**1 +1 ....
  1486. that is, 
  1487. the k-th term in the sequence is 
  1488. 100**k + 100**(k-1) + 100**(k-2) + ...+ 100**(1) + 1
  1489. = (100)**(k+1) - 1
  1490.   ----------------
  1491.     11 * 9
  1492. = (10)**(2k+2) - 1
  1493.   ----------------
  1494.     11 * 9
  1495. = ((10)**(k+1) - 1)*((10)**(k+1) +1)
  1496.    ---------------------------------
  1497.        11*9
  1498. thus either 11 and 9 divide the numerator. Either they both divide the
  1499. same factor in the numerator or different factors in the numerator. In
  1500. any case, after dividing, they leave the numerators as a product of two
  1501. integers.  Only in the case of k = 1, one of the integers is 1. Thus
  1502. there is exactly one prime in the above sequence: 101.
  1503.  
  1504. ==> arithmetic/digits/prime/all.prefix.p <==
  1505. What is the longest prime whose every proper prefix is a prime?
  1506.  
  1507. ==> arithmetic/digits/prime/all.prefix.s <==
  1508. 23399339, 29399999, 37337999, 59393339, 73939133
  1509.  
  1510. ==> arithmetic/digits/prime/change.one.p <==
  1511. What is the smallest number that cannot be made prime by changing a single
  1512. digit?  Are there infinitely many such numbers?
  1513.  
  1514. ==> arithmetic/digits/prime/change.one.s <==
  1515. 200.  Obviously, you would have to change the last digit, but 201, 203,
  1516. 207, and 209 are all composite.  For any smaller number, you can change
  1517. the last digit, and get
  1518. 2,11,23,31,41,53,61,71,83,97,101,113,127,131,149,151,163,173,181, or 191.
  1519.  
  1520. 200+2310n gives an infinite family, because changing the last
  1521. digit to 1 or 7 gives a number divisible by 3; to 3, a number divisible
  1522. by 7; to 9, a number divisible by 11.
  1523.  
  1524. ==> arithmetic/digits/prime/prefix.one.p <==
  1525. 2 is prime, but 12, 22, ..., 92 are not.  Similarly, 5 is prime
  1526. whereas 15, 25, ..., 95 are not.  What is the next prime number
  1527. which is composite when any digit is prefixed?
  1528.  
  1529. ==> arithmetic/digits/prime/prefix.one.s <==
  1530. 149
  1531.  
  1532. ==> arithmetic/digits/reverse.p <==
  1533. Is there an integer that has its digits reversed after dividing it by 2?
  1534.  
  1535. ==> arithmetic/digits/reverse.s <==
  1536. Assume there's such a positive integer x such that x/2=y and y is the
  1537. reverse of x.
  1538.  
  1539. Then x=2y.  Let x = a...b, then y = b...a, and:
  1540.  
  1541.                  b...a   (y)
  1542.            x     2
  1543.                --------
  1544.                  a...b   (x)
  1545.  
  1546. From the last digit b of x, we have b = 2a (mod 10), the possible
  1547. values for b are 2, 4, 6, 8 and hence possible values for (a, b) are
  1548. (1,2), (6,2), (2,4), (7,4), (3,6), (8,6), (4,8), (9,8).
  1549.  
  1550. From the first digit a of x, we have a = 2b or a = 2b+1.  None of the
  1551. above pairs satisfy this condition.  A contradiction.
  1552.  
  1553. Hence there's no such integer.
  1554.  
  1555. ==> arithmetic/digits/rotate.p <==
  1556. Find integers where multiplying them by single digits rotates their digits.
  1557.  
  1558. ==> arithmetic/digits/rotate.s <==
  1559. 2 105263157894736842
  1560. 3 1034482758620689655172413793
  1561. 4 102564 153846 179487 205128 230769
  1562. 5 142857 102040816326530612244897959183673469387755
  1563. 6 1016949152542372881355932203389830508474576271186440677966
  1564.   1186440677966101694915254237288135593220338983050847457627
  1565.   1355932203389830508474576271186440677966101694915254237288
  1566.   1525423728813559322033898305084745762711864406779661016949
  1567. 7 1014492753623188405797 1159420289855072463768 1304347826086956521739
  1568. 8 1012658227848 1139240506329
  1569. 9 10112359550561797752808988764044943820224719
  1570.  
  1571. In base B, suppose you have an N-digit answer A whose digits are
  1572. rotated when multiplied by K.  If D is the low-order digit of A, we
  1573. have
  1574.  
  1575.     (A-D)/B + D B^(N-1) = K A .
  1576.  
  1577. Solving this for A we have
  1578.  
  1579.         D (B^N - 1)
  1580.     A = ----------- .
  1581.           B K - 1
  1582.  
  1583. In order for A >= B^(N-1) we must have D >= K.  Now we have to find N
  1584. such that B^N-1 is divisible by R=(BK-1)/gcd(BK-1,D).  This always has
  1585. a minimal solution N0(R,B)<R, and the set of all solutions is the set
  1586. of multiples of N0(R,B).  N0(R,B) is the length of the repeating part
  1587. of the fraction 1/R in base B.
  1588.  
  1589. N0(ST,B)=N0(S,B)N0(T,B) when (S,T)=1, and for prime powers, N0(P^X,B)
  1590. divides (P-1)P^(X-1). Determining which divisor is a little more
  1591. complicated but well-known (cf. Hardy & Wright).
  1592.  
  1593. So given B and K, there is one minimal solution for each
  1594. D=K,K+1,...,B-1, and you get all the solutions by taking repetitions
  1595. of the minimal solutions.
  1596.  
  1597. ==> arithmetic/digits/sesqui.p <==
  1598. Find the least number where moving the first digit to the end multiplies by 1.5.
  1599.  
  1600.